<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * 检测用户登录
 * @param array $data 登录数据
 * @return boolean
 * @since 1.0 <2015-10-19> SoChishun Added.
 */
function user_check_login(&$data = '', $refresh = true) {
    $data = session('login');
    if (!$data) {
        return false;
    }
    // 页面刷新的时候刷新用户登录信息,以同步个人资料编辑 2016-2-15 SoChishun Added.
    if ($refresh) {
        $m_login = new \XWAM\Model\LoginModel();
        $status = $m_login->refresh_login_info($data);
        if (true === $status) {
            session('login', $data);
        } else if ('E_ACCOUNT_DISABLED' == $status) {
            E('帐户已禁用!');
        }
    }
    return true;
}

/**
 * 通用获取状态名称方法
 * @param string $v 值
 * @param string $type 类型
 *      yesno=否|是,activate=未激活|已激活,approval=未审核|已审核,startstop=已停止|已启动|已暂停,enable=已禁用|已启用,login:登出|登入,user=正常|待审核|禁用,sex=女士|先生|保密,marital=未婚|已婚|保密
 * @return string
 * @since 1.0 2014-7-7 by sutroon, 2014-12-3 新增$undefined
 * @example {$vo.state|sofn_get_state_text=user,###}
 */
function sofn_get_state_text($type, $v, $undefined = null) {
    $set = false;
    switch (strtolower($type)) {
        case 'user-state':
            $set = array('0' => '待审核', '1' => '正常', '3' => '冻结', '4' => '禁用', '7' => '注销', '14' => '回收站');
            break;
        case 'online-state':
            $set = array('0' => '离线', '1' => '在线', '2' => '隐身', '3' => '离开', '5' => '忙碌');
            break;
        case 'start-stop':
            $set = array('0' => '已停止', '1' => '已启动', '2' => '已暂停');
            break;
        case 'activate-state':
            $set = array('0' => '未激活', '1' => '已激活');
            break;
        case 'yes-no':
            $set = array('0' => '否', '1' => '是', 'N' => '否', 'Y' => '是', 'F' => '否', 'T' => '是');
            break;
        case 'success-fail':
            $set = array('0' => '失败', '1' => '成功', 'N' => '失败', 'Y' => '成功');
            break;
        case 'display-hide':
            $set = array('0' => '隐藏', '1' => '显示', 'N' => '隐藏', 'Y' => '显示');
            break;
        case 'approval-state':
            $set = array('0' => '未审核', '1' => '已审核', '4' => '已关闭');
            break;
        case 'enable':
            $set = array('0' => '已禁用', '1' => '已启用');
            break;
        case 'login':
            $set = array('0' => '已登出', '1' => '已登入');
            break;
        case 'sex':
            $set = array('0' => '女士', '1' => '先生', '2' => '保密');
            break;
        case 'marital':
            $set = array('0' => '未婚', '1' => '已婚', '2' => '保密');
            break;
        case 'cti-call-result':
            $set = array('ANSWERED' => '应答', 'NO ANSWER' => '无应答', 'CONGESTION' => '堵塞', 'BUSY' => '忙音', 'FAILED' => '失败');
            break;
        case 'cti-channel-state':
            $set = array('0' => '空闲', '1' => '正在呼叫', '2' => '通话中', '3' => '呼叫成功', '4' => '呼叫失败');
            break;
        case 'cti-call-forwarding-type':
            $set = array('0' => '', '1' => '无条件转接', '2' => '忙时转移', '3' => '无应答或不可用时转移');
            break;
        case 'message-send-state':
            $set = array('0' => '未发送', '1' => '发送成功', '2' => '发送失败');
            break;
        case 'record-source':
            $set = array('import' => '导入', 'add' => '添加', 'generate' => '生成');
            break;
        case 'pay-type':
            $set = array('0' => '后付费', '1' => '预付费');
            break;
        case 'settlement-status':
            $set = array('0' => '未结算', '1' => '已结清', '2' => '部分结算');
            break;
        case 'confirm':
            $set = array('0' => '未审核', '1' => '审核通过', '4' => '审核拒绝');
            break;
        case 'input-type':
            $set = array('text' => '字符输入框', 'int' => '数字输入框', 'decimal' => '小数输入框', 'email' => '邮件输入框', 'mobile' => '手机号码输入框', 'telphone' => '电话号码输入框', 'date' => '日期选择框(xxxx-xx-xx)', 'datetime' => '日期和时间选择框(xxxx-xx-xx xx:xx:xx)', 'time' => '时间选择框(xx:xx)', 'select' => '下拉选择框', 'radio' => '单选框', 'checkbox' => '复选框', 'textarea' => '多行文本框', 'editor' => '可视化编辑器', 'file' => '文件上传框');
            break;
        case 'product-sale-state': // 商品销售状态
            $set = array('0' => '下架', '1' => '上架');
            break;
        case 'product-invoicing-operate-type': // 商品进销存操作类型 2014-12-23 by sutroon
            $set = array('SELL-RETURN' => '销售退货(入库)', 'SALE' => '销售出库', 'PURCHASE' => '采购入库', 'INTERNAL' => '内部出库', 'INVENTORY' => '盘点调仓');
            break;
        case 'customer-appointment-status': // 客户预约状态 2014-12-24 by sutroon
            $set = array('0' => '未回访', '1' => '回访成功', '2' => '回访失败', '4' => '放弃回访');
            break;
        case 'customer-appointment-type': // 客户预约来源 2014-12-24 by sutroon
            $set = array('USER' => '自定义', 'ORDER' => '订单回访');
            break;
        case 'customer-buy-interested': // 客户购买意向 2014-12-25 by sutroon
            $set = array('0' => '普通', '1' => '意向购买', '2' => '非常兴趣');
            break;
        case 'is-search-condition':
            $set = array('N' => '不搜索', 'EQ' => '精确匹配', 'LIKE' => '模糊匹配', 'ELT' => '小于等于', 'EGT' => '大于等于');
            break;
        case 'settlement-state':
            $set = array('0' => '未结算', '1' => '已结算');
            break;
        case 'invoicing-direction':
            $set = array('I' => '入库', 'O' => '出库');
            break;
        case 'channel-type':
            $set = array('page' => '单独页面', 'document-list' => '文章栏目', 'file-list' => '下载栏目','node'=>'普通节点', 'ulink' => '分类链接', 'url' => '链接地址');
            break; 
    }
    $str = false;
    if ($set) {
        if (array_key_exists($v, $set)) {
            $str = $set[$v];
        } else if (array_key_exists('*', $set)) {
            $str = $set['*'];
        } else {
            $str = '';
        }
    }
    if (false === $str) {
        $str = is_null($undefined) ? "[$type|$v]" : $undefined;
    }
    return $str;
}